package first;

import java.io.*;

public class ReandFileBean {
    private String  username;
    private String  password;
    private  String url;
    private String  postbox;
    private String  fname;
    private String  sname;
    private String  department;
    private String  object;

    public ReandFileBean() {}

    public String getUsername(){
        return username;
    }

    public void setUsername(String username){
        this.username=username;
    }

    public String getPassword(){
        return password;
    }

    public void setPassword(String password){
        this.password=password;
    }

    public String getUrl(){
        return url;
    }

    public void setUrl(String url){
        this.url=url;
    }

    public String getPostbox(){
        return postbox;
    }
    public void setPostbox(String postbox){
        this.postbox=postbox;
    }

    public void setFname(String fname){ this.fname=fname; }
    public String getFname(){ return fname; }

    public void setSname(String sname){ this.sname=sname; }
    public String getSname(){ return sname; }

    public void setDepartment(String department){ this.department=department; }
    public String getDepartment(){ return department; }

    public void setObject(String object){ this.object=object; }
    public String getObject(){ return object; }


    public void Read(String username){

        File fread = new File("Student.txt");

        try {
            Reader in =new FileReader(fread);
            BufferedReader bufferRead =new BufferedReader(in);
            String str=null;
            String[] massege;
            while((str=bufferRead.readLine())!=null){
                massege=str.split(",");
                if(massege[0].equals(username)){
                    this.username=massege[0];
                    this.password=massege[1];
                    this.postbox=massege[2];
                    this.fname=massege[3];
                    this.sname=massege[4];
                    this.department=massege[5];
                    this.object=massege[6];
                    this.url=massege[7];
                    break;
                }
            }
            bufferRead.close();
            in.close();
        }
        catch(IOException e){
            System.out.println(e.toString());
        }
    }
    public static void main(String[] args) {
       ReandFileBean s1=new ReandFileBean();
       s1.Read("2");
       System.out.println(s1.getUsername());
        System.out.println(s1.getPassword());
   }

}
